function register(){

    let userName = $("#userName").val();
    let userPassword = $("#userPassword").val();
    let checkPassword = $("#checkPassword").val();
    let userLoginName = $("#userLoginName").val();
    let data = {
        "userName": userName,
        "userPassword": userPassword,
        "userLoginName": userLoginName,
        "checkPassword":checkPassword,
        "_method": "PUT",
        action:"register"
    };
    if(userLoginName.length<=7 || userLoginName.length>11 ) {
        alert("登陆名长度必须大于7且小于11！");
        return false;
    }
    if (NonEmpty && isUse){
        $.ajax({
            url: getRealPath()+"/userServlet",
            "data": data,
            method: "POST",
            dataType: "json",
            success: function (result) {
                if(result.status === 1){
                    window.location.href = getRealPath()+"/login.jsp";
                }
                alert(result.message);
            }
        });
    }

}
//回车提交
function enterCommit(key){
    let keyNum;
    if(window.event)
    {
        keyNum = key.keyCode;
    }
    else if(key.which)
    {
        keyNum = key.which;
    }
    //按下回车键
    if(keyNum === 13){
        isUse();
        register();
    }
}
/**
 * 查看登入名是否可用
 */
function isUse(){

    let userLoginName = $("#userLoginName").val();
    if(userLoginName.length<=7 || userLoginName.length>11 ) {
        alert("登陆名长度必须大于7且小于11！");
        return false;
    }
    else {
        $.ajax({
            url: getRealPath()+"/userServlet",
            data: {
                "userLoginName": userLoginName,
                action:"repetitionLoginName"
            },
            method: "POST",
            dataType: "json",
            success: function (result) {
                document.getElementById("userLoginNameMessage").innerHTML=result.message;
            }
        });
    }
}

function NonEmpty () {
    let userName = $("#userName").val();
    let userPassword = $("#userPassword").val();
    let checkPassword = $("#checkPassword").val();
    let userLoginName = $("#userLoginName").val();
    if(userName === ""){
        alert("用户名不能为空！");
        return false;
    }
    if(userName.length>11){
        alert("用户名长度不能大于11位")
        return false;
    }
    if(userLoginName === ""){
        alert("登入名不能为空！");
        return false;
    }
    if(userPassword === null || checkPassword === null || userPassword.replace(/^\s+|\s+$/g,"").length === 0 || checkPassword.replace(/^\s+|\s+$/g,"").length === 0){
        alert("密码和确认密码不能为空！");
        return false;
    }
    if(userPassword.length<=7||userLoginName.length>=19) {
        alert("密码长度必须大于7且小于19！");
        return false;
    }
    if(userPassword !== checkPassword){
        alert("密码和确认密码不一致！");
        return false;
    }
    else {
        register();
    }

}


